from pms.common.views import PostFormula
from info.models import MailReceive
from info.utils.mail import mail_view


class API(PostFormula):
    def handle(self, req):
        try:
            receive = MailReceive.objects.get(uid=self.user, mid_id=req['id'])
        except MailReceive.DoesNotExist:
            return self.failed_respond('MAIL_INVISIBLE', '邮件对用户不可见')
        if receive.is_delete is True:
            return self.failed_respond('MAIL_INVISIBLE', '邮件对用户不可见')
        return self.success_respond(mail_view(receive.mid))
